package com.massa.caronafacil.activities;

import com.massa.caronafacil.R;
import com.massa.caronafacil.db.SQLConnector;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class BuscarCaronasActivity extends Activity implements OnClickListener {

	private EditText nomeCaronaEditText;
	private Button okBuscarCaronabutton;

    @Override
    protected final void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Inflate the layout
        setContentView(R.layout.buscar_caronas_layout);
        
        nomeCaronaEditText = (EditText) findViewById(R.id.editTextNomeCarona);
        okBuscarCaronabutton = (Button) findViewById(R.id.buttonOkBuscarCarona);
        okBuscarCaronabutton.setOnClickListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected final void onSaveInstanceState(final Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

	@Override
	public void onClick(View v) {
        if (v != null) {
            switch (v.getId()) {
            case R.id.buttonOkBuscarCarona:
            	buscarCarona();
                break;
            }
        }
	}

	public void buscarCarona() {
		//nomeCaronaEditText.getText().toString()
		Connection conn = SQLConnector.getInstance().getConn();

		try {
			Statement stmt = conn.createStatement();
			ResultSet reset = stmt.executeQuery("select * from TableName");
			 
			//TODO: buscar carona nas tabelas
			while(reset.next()){
				Log.w("Data:",reset.getString(3));
				//	              Log.w("Data",reset.getString(2));
			}
		} catch (Exception e) {
			Log.w("Error connection","" + e.getMessage());
		}
	}
}
